package com.irdstudio.cdp.pboc.service.impl;

import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.cdp.pboc.service.dao.PbocNoneworkoffNearcreditcardDao;
import com.irdstudio.cdp.pboc.service.domain.PbocNoneworkoffNearcreditcard;
import com.irdstudio.cdp.pboc.service.facade.PbocNoneworkoffNearcreditcardService;
import com.irdstudio.cdp.pboc.service.vo.PbocNoneworkoffNearcreditcardVO;
import com.irdstudio.basic.framework.core.base.FrameworkService;
/**
 * <p>ServiceImpl: 未销户准贷记卡信息汇总				<p>
 * @author ligm
 * @date 2018-12-26
 */
@Service("pbocNoneworkoffNearcreditcardService")
public class PbocNoneworkoffNearcreditcardServiceImpl implements PbocNoneworkoffNearcreditcardService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(PbocNoneworkoffNearcreditcardServiceImpl.class);

	@Autowired
	private PbocNoneworkoffNearcreditcardDao pbocNoneworkoffNearcreditcardDao;
	
	/**
	 * 新增操作
	 */
	public int insertPbocNoneworkoffNearcreditcard(PbocNoneworkoffNearcreditcardVO inPbocNoneworkoffNearcreditcardVo)  throws Exception {
		logger.debug("当前新增数据为:"+ inPbocNoneworkoffNearcreditcardVo.toString());
		int num = 0;
		try {
			PbocNoneworkoffNearcreditcard pbocNoneworkoffNearcreditcard = new PbocNoneworkoffNearcreditcard();
			beanCopy(inPbocNoneworkoffNearcreditcardVo, pbocNoneworkoffNearcreditcard);
			num = pbocNoneworkoffNearcreditcardDao.insertPbocNoneworkoffNearcreditcard(pbocNoneworkoffNearcreditcard);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(PbocNoneworkoffNearcreditcardVO inPbocNoneworkoffNearcreditcardVo)  throws Exception {
		logger.debug("当前删除数据条件为:"+ inPbocNoneworkoffNearcreditcardVo);
		int num = 0;
		try {
			PbocNoneworkoffNearcreditcard pbocNoneworkoffNearcreditcard = new PbocNoneworkoffNearcreditcard();
			beanCopy(inPbocNoneworkoffNearcreditcardVo, pbocNoneworkoffNearcreditcard);
			num = pbocNoneworkoffNearcreditcardDao.deleteByPk(pbocNoneworkoffNearcreditcard);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("根据条件:"+ inPbocNoneworkoffNearcreditcardVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(PbocNoneworkoffNearcreditcardVO inPbocNoneworkoffNearcreditcardVo)  throws Exception {
		logger.debug("当前修改数据为:"+ inPbocNoneworkoffNearcreditcardVo.toString());
		int num = 0;
		try {
			PbocNoneworkoffNearcreditcard pbocNoneworkoffNearcreditcard = new PbocNoneworkoffNearcreditcard();
			beanCopy(inPbocNoneworkoffNearcreditcardVo, pbocNoneworkoffNearcreditcard);
			num = pbocNoneworkoffNearcreditcardDao.updateByPk(pbocNoneworkoffNearcreditcard);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("根据条件:"+ inPbocNoneworkoffNearcreditcardVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public PbocNoneworkoffNearcreditcardVO queryByPk(PbocNoneworkoffNearcreditcardVO inPbocNoneworkoffNearcreditcardVo) {
		
		logger.debug("当前查询参数信息为:"+ inPbocNoneworkoffNearcreditcardVo);
		try {
			PbocNoneworkoffNearcreditcard queryPbocNoneworkoffNearcreditcard = new PbocNoneworkoffNearcreditcard();
			beanCopy(inPbocNoneworkoffNearcreditcardVo, queryPbocNoneworkoffNearcreditcard);
			PbocNoneworkoffNearcreditcard queryRslPbocNoneworkoffNearcreditcard = pbocNoneworkoffNearcreditcardDao.queryByPk(queryPbocNoneworkoffNearcreditcard);
			if (Objects.nonNull(queryRslPbocNoneworkoffNearcreditcard)) {
				PbocNoneworkoffNearcreditcardVO outPbocNoneworkoffNearcreditcardVo = beanCopy(queryRslPbocNoneworkoffNearcreditcard, new PbocNoneworkoffNearcreditcardVO());
				logger.debug("当前查询结果为:"+ outPbocNoneworkoffNearcreditcardVo.toString());
				return outPbocNoneworkoffNearcreditcardVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
			throw e;
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocNoneworkoffNearcreditcardVO> queryAllOwner(PbocNoneworkoffNearcreditcardVO pbocNoneworkoffNearcreditcardVo)  throws Exception {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<PbocNoneworkoffNearcreditcardVO> list = null;
		try {
			List<PbocNoneworkoffNearcreditcard> pbocNoneworkoffNearcreditcards = pbocNoneworkoffNearcreditcardDao.queryAllOwnerByPage(pbocNoneworkoffNearcreditcardVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ pbocNoneworkoffNearcreditcards.size());
			pageSet(pbocNoneworkoffNearcreditcards, pbocNoneworkoffNearcreditcardVo);
			list = (List<PbocNoneworkoffNearcreditcardVO>) beansCopy(pbocNoneworkoffNearcreditcards, PbocNoneworkoffNearcreditcardVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocNoneworkoffNearcreditcardVO> queryAllCurrOrg(PbocNoneworkoffNearcreditcardVO pbocNoneworkoffNearcreditcardVo)  throws Exception {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<PbocNoneworkoffNearcreditcard> pbocNoneworkoffNearcreditcards = pbocNoneworkoffNearcreditcardDao.queryAllCurrOrgByPage(pbocNoneworkoffNearcreditcardVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+pbocNoneworkoffNearcreditcards.size());
		List<PbocNoneworkoffNearcreditcardVO> list = null;
		try {
			pageSet(pbocNoneworkoffNearcreditcards, pbocNoneworkoffNearcreditcardVo);
			list = (List<PbocNoneworkoffNearcreditcardVO>) beansCopy(pbocNoneworkoffNearcreditcards, PbocNoneworkoffNearcreditcardVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocNoneworkoffNearcreditcardVO> queryAllCurrDownOrg(PbocNoneworkoffNearcreditcardVO pbocNoneworkoffNearcreditcardVo)  throws Exception {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<PbocNoneworkoffNearcreditcard> pbocNoneworkoffNearcreditcards = pbocNoneworkoffNearcreditcardDao.queryAllCurrDownOrgByPage(pbocNoneworkoffNearcreditcardVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ pbocNoneworkoffNearcreditcards.size());
		List<PbocNoneworkoffNearcreditcardVO> list = null;
		try {
			pageSet(pbocNoneworkoffNearcreditcards, pbocNoneworkoffNearcreditcardVo);
			list = (List<PbocNoneworkoffNearcreditcardVO>) beansCopy(pbocNoneworkoffNearcreditcards, PbocNoneworkoffNearcreditcardVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}

	/**
	 * 需求编号:2019D0519
	 * 问题编号:2019D0519
	 * 开发人员: caoxin
	 * 创建日期:2019/7/19
	 * 功能描述:未销户准贷记卡信息汇总
	 * 修改日期:2019/7/19
	 * 修改描述:
	 */
//	@author:liuty
//	@date:2019/10/17
//	涉及产品:税e贷
//	功能:未销户准贷记卡信息汇总
//	原因:增量投产只投了接口没投实现，编译报错因此注释，不影响实际业务
//	public PbocNoneworkoffNearcreditcardVO queryByReportId(PbocNoneworkoffNearcreditcardVO inPbocNoneworkoffNearcreditcardVo) {
//
//		logger.debug("当前查询参数信息为:"+ inPbocNoneworkoffNearcreditcardVo);
//		try {
//			PbocNoneworkoffNearcreditcard queryPbocNoneworkoffNearcreditcard = new PbocNoneworkoffNearcreditcard();
//			beanCopy(inPbocNoneworkoffNearcreditcardVo, queryPbocNoneworkoffNearcreditcard);
//			PbocNoneworkoffNearcreditcard queryRslPbocNoneworkoffNearcreditcard = pbocNoneworkoffNearcreditcardDao.queryByReportId(queryPbocNoneworkoffNearcreditcard);
//			if (Objects.nonNull(queryRslPbocNoneworkoffNearcreditcard)) {
//				PbocNoneworkoffNearcreditcardVO outPbocNoneworkoffNearcreditcardVo = beanCopy(queryRslPbocNoneworkoffNearcreditcard, new PbocNoneworkoffNearcreditcardVO());
//				logger.debug("当前查询结果为:"+ outPbocNoneworkoffNearcreditcardVo.toString());
//				return outPbocNoneworkoffNearcreditcardVo;
//			} else {
//				logger.debug("当前查询结果为空!");
//			}
//		} catch (Exception e) {
//			logger.error("查询数据发生异常!", e);
//			throw e;
//		}
//		return null;
//	}

}
